package com.gitee.xmhzzz.mqtt.quick.config;

import com.gitee.xmhzzz.mqtt.quick.client.MyMqttClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName MqttConfigration
 * @Description
 * @Author wzq
 * @Date 2024/1/14 14:52
 * @Version 1.0
 */
@Configuration
@ConditionalOnProperty(value = "mqtt.enable", havingValue = "true")
public class MqttConfiguration {

    @Bean
    @ConfigurationProperties(prefix = "mqtt")
    public MqttConfig mqttConfig() {
        return new MqttConfig();
    }
    /**
     * 订阅mqtt
     *
     * @return
     */
    @Bean
    public MyMqttClient getMqttPushClient(MqttConfig mqttConfig) {
        MyMqttClient myMqttClient = new MyMqttClient(mqttConfig);
        myMqttClient.connect();
        return myMqttClient;
    }


}
